Skip to content

Warn for string-to-literal narrowing assignments - #19603

Open
Engin Polat (polatengin) wants to merge 3 commits into
mainfrom
polatengin/11889-narrowing-assignment-to-union-typed-receiver-should-generate-warning-not-error
Open

Warn for string-to-literal narrowing assignments#19603
Engin Polat (polatengin) wants to merge 3 commits into
mainfrom
polatengin/11889-narrowing-assignment-to-union-typed-receiver-should-generate-warning-not-error

Conversation

@polatengin

@polatengin Engin Polat (polatengin) commented May 5, 2026

Copy link
Copy Markdown
Member

Description

Allows assignments from plain string values to fixed string-literal receivers, such as 'foo' | 'bar', to compile with a warning when the value may be valid at runtime.

The assignment is treated as narrowed to the receiver’s allowed string literals, matching existing narrowing behavior for bounded values.

Fixes #11889

Example Usage

// mod.bicep
@allowed(['foo', 'bar'])
param foobar string

// main.bicep
param foobar string
module mod './mod.bicep' = {
  name: 'mod'
  params: {
    foobar: foobar
  }
}

This now emits warning-level BCP036 instead of error-level BCP036

Checklist

Microsoft Reviewers: Open in CodeFlow

@github-actions

github-actions Bot commented May 5, 2026

Copy link
Copy Markdown
Contributor

Test this change out locally with the following install scripts (Action run 25392104965)

VSCode
  • Mac/Linux
    bash <(curl -Ls https://aka.ms/bicep/nightly-vsix.sh) --run-id 25392104965
  • Windows
    iex "& { $(irm https://aka.ms/bicep/nightly-vsix.ps1) } -RunId 25392104965"
Azure CLI
  • Mac/Linux
    bash <(curl -Ls https://aka.ms/bicep/nightly-cli.sh) --run-id 25392104965
  • Windows
    iex "& { $(irm https://aka.ms/bicep/nightly-cli.ps1) } -RunId 25392104965"

@stephaniezyen stephaniezyen modified the milestones: v0.41, 0.44 May 6, 2026
@polatengin
Engin Polat (polatengin) enabled auto-merge (squash) May 29, 2026 18:43
@stephaniezyen stephaniezyen modified the milestones: v0.44, v0.45 Jun 24, 2026
@stephaniezyen stephaniezyen modified the milestones: v0.45, v0.46 Jul 21, 2026
@stephaniezyen stephaniezyen modified the milestones: v0.46, v0.47 Aug 5, 2026
@stephaniezyen stephaniezyen moved this from Todo to In Review in Bicep Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

Narrowing assignment to union typed receiver should generate warning, not error

2 participants